package org.example.controller;

import org.example.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class ConsumerController {


    @Resource
    private UserService userService;   //第一种使用openFeign的方式访问微服务的接口

    @Resource
    private RestTemplate restTemplate; //通过springBoot原生态的RestTemplate访问


    @GetMapping(value = "/getProviderName")
    public String getProviderName(){
        return userService.getTest();
    }

    @GetMapping(value = "/getUserInfo/{id}")
    public String getUserInfo(@PathVariable Integer id){
        return userService.getUser(id);
    }

    @GetMapping(value = "/getUserByRest/{id}")
    public String getUserInfoByRest(@PathVariable Integer id){
      return  restTemplate.getForObject("http://provider-server/provider/user/getById/".concat(id.toString()),String.class);
    }


}
